package 数据库.day2;

import 数据库.练习.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
//1：统计各种性别的人数，并输出
public class StatisStudent {
    public static void main(String[] args) {
        Connection con=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            con= DBUtil.getConnection();
            ps=con.prepareStatement("select sex, COUNT(stuno)  from s_student  group by sex");
            rs=ps.executeQuery();
            while (rs.next()){
                System.out.println(rs.getString("sex")+"有"+rs.getString("COUNT(stuno)")+"人");
            }
        } catch (SQLException e) {
           e.printStackTrace();
        }finally {
            DBUtil.close(rs,ps,con);
        }
    }
}
